import { showConfirmDialog } from "vant";

const routes = [
  {
    path: "/",
    name: "index",
    redirect: "/home",
    component: () => import("@/views/Index.vue"),
    children: [
      {
        path: "home",
        name: "home",
        component: () => import("@/views/tabbar/Home.vue"),
      },
      {
        path: "classify",
        name: "classify",
        component: () => import("@/views/tabbar/Classify.vue"),
      },
      {
        path: "user",
        name: "user",
        component: () => import("@/views/tabbar/User.vue"),
      },
    ],
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/Login.vue"),
    children: [],
  },
  {
    path: "/register",
    name: "register",
    component: () => import("../views/Register.vue"),
  },

  // 404页面路由
  {
    path: "/:pathMatch(.*)*",
    name: "404",
    component: () => import("@/views/NotFound.vue"),
  },

  // 分类模块的子路由
  {
    path: "/classifys",
    name: "classifys",
    children: [
      {
        path: "menwear",
        name: "menwear",
        component: () => import("@/views/classify/MenWear.vue"),
      },
      {
        path: "womenwear",
        name: "womenwear",
        component: () => import("@/views/classify/WomenWear.vue"),
      },
      {
        path: "dailyuse",
        name: "dailyuse",
        component: () => import("@/views/classify/DailyUse.vue"),
      },
      {
        path: "techno",
        name: "techno",
        component: () => import("@/views/classify/Techno.vue"),
      },
      {
        path: "exercise",
        name: "exercise",
        component: () => import("@/views/classify/Exercise.vue"),
      },
      {
        path: "box",
        name: "box",
        component: () => import("@/views/classify/Box.vue"),
      },
      {
        path: "mother",
        name: "mother",
        component: () => import("@/views/classify/Mother.vue"),
      },
      {
        path: "perfume",
        name: "perfume",
        component: () => import("@/views/classify/Perfume.vue"),
      },
    ],
  },
  //我的 模块路由
  {
    path: "/users",
    name: "users",
    children: [
      {
        path: "aftersale",
        name: "aftersale",
        component: () => import("@/views/user/AfterSale.vue"),
        beforeEnter: (to, from, next) => {
          if (localStorage.token === undefined) {
            showConfirmDialog({
              title: "请先登录",
              message: "你还没有登录,需要跳转到登录页吗?(*^▽^*)",
            })
              .then(() => {
                next("/login");
              })
              .catch(() => {
                next(from.path);
              });
          } else {
            next();
          }
        },
      },
      {
        path: "contactus",
        name: "contactus",
        component: () => import("@/views/user/ContactUs.vue"),
        beforeEnter: (to, from, next) => {
          if (localStorage.token === undefined) {
            showConfirmDialog({
              title: "请先登录",
              message: "你还没有登录,需要跳转到登录页吗?(*^▽^*)",
            })
              .then(() => {
                next("/login");
              })
              .catch(() => {
                next(from.path);
              });
          } else {
            next();
          }
        },
      },
      {
        path: "footprint",
        name: "footprint",
        component: () => import("@/views/user/Footprint.vue"),
        beforeEnter: (to, from, next) => {
          if (localStorage.token === undefined) {
            showConfirmDialog({
              title: "请先登录",
              message: "你还没有登录,需要跳转到登录页吗?(*^▽^*)",
            })
              .then(() => {
                next("/login");
              })
              .catch(() => {
                next(from.path);
              });
          } else {
            next();
          }
        },
      },
      {
        path: "location",
        name: "location",
        component: () => import("@/views/user/Location.vue"),
        beforeEnter: (to, from, next) => {
          if (localStorage.token === undefined) {
            showConfirmDialog({
              title: "请先登录",
              message: "你还没有登录,需要跳转到登录页吗?(*^▽^*)",
            })
              .then(() => {
                next("/login");
              })
              .catch(() => {
                next(from.path);
              });
          } else {
            next();
          }
        },
      },
      {
        path: "order",
        name: "order",
        component: () => import("@/views/user/Order.vue"),
        beforeEnter: (to, from, next) => {
          if (localStorage.token === undefined) {
            showConfirmDialog({
              title: "请先登录",
              message: "你还没有登录,需要跳转到登录页吗?(*^▽^*)",
            })
              .then(() => {
                next("/login");
              })
              .catch(() => {
                next(from.path);
              });
          } else {
            next();
          }
        },
      },
      {
        path: "awaitorder",
        name: "awaitorder",
        component: () => import("@/views/order/AwaitOrder.vue"),
        beforeEnter: (to, from, next) => {
          if (localStorage.token === undefined) {
            showConfirmDialog({
              title: "请先登录",
              message: "你还没有登录,需要跳转到登录页吗?(*^▽^*)",
            })
              .then(() => {
                next("/login");
              })
              .catch(() => {
                next(from.path);
              });
          } else {
            next();
          }
        },
      },
      {
        path: "failureorder",
        name: "failureorder",
        component: () => import("@/views/order/FailureOrder.vue"),
        beforeEnter: (to, from, next) => {
          if (localStorage.token === undefined) {
            showConfirmDialog({
              title: "请先登录",
              message: "你还没有登录,需要跳转到登录页吗?(*^▽^*)",
            })
              .then(() => {
                next("/login");
              })
              .catch(() => {
                next(from.path);
              });
          } else {
            next();
          }
        },
      },
      {
        path: "finishorder",
        name: "finishorder",
        component: () => import("@/views/order/Finishorder.vue"),
        beforeEnter: (to, from, next) => {
          if (localStorage.token === undefined) {
            showConfirmDialog({
              title: "请先登录",
              message: "你还没有登录,需要跳转到登录页吗?(*^▽^*)",
            })
              .then(() => {
                next("/login");
              })
              .catch(() => {
                next(from.path);
              });
          } else {
            next();
          }
        },
      },
      {
        path: "obligationorder",
        name: "obligationorder",
        component: () => import("@/views/order/ObligationOrder.vue"),
        beforeEnter: (to, from, next) => {
          if (localStorage.token === undefined) {
            showConfirmDialog({
              title: "请先登录",
              message: "你还没有登录,需要跳转到登录页吗?(*^▽^*)",
            })
              .then(() => {
                next("/login");
              })
              .catch(() => {
                next(from.path);
              });
          } else {
            next();
          }
        },
      },
      {
        path: "receivingorder",
        name: "receivingorder",
        component: () => import("@/views/order/ReceivingOrder.vue"),
        beforeEnter: (to, from, next) => {
          if (localStorage.token === undefined) {
            showConfirmDialog({
              title: "请先登录",
              message: "你还没有登录,需要跳转到登录页吗?(*^▽^*)",
            })
              .then(() => {
                next("/login");
              })
              .catch(() => {
                next(from.path);
              });
          } else {
            next();
          }
        },
      },
      {
        path: "aboutus",
        name: "aboutus",
        component: () => import("@/views/user/AboutUs.vue"),
        beforeEnter: (to, from, next) => {
          if (localStorage.token === undefined) {
            showConfirmDialog({
              title: "请先登录",
              message: "你还没有登录,需要跳转到登录页吗?(*^▽^*)",
            })
              .then(() => {
                next("/login");
              })
              .catch(() => {
                next(from.path);
              });
          } else {
            next();
          }
        },
      },
      {
        path: "changepwd",
        name: "changepwd",
        component: () => import("@/views/user/ChangePwd.vue"),
        beforeEnter: (to, from, next) => {
          if (localStorage.token === undefined) {
            showConfirmDialog({
              title: "请先登录",
              message: "你还没有登录,需要跳转到登录页吗?(*^▽^*)",
            })
              .then(() => {
                next("/login");
              })
              .catch(() => {
                next(from.path);
              });
          } else {
            next();
          }
        },
      },
      {
        path: "personalinformation",
        name: "personalinformation",
        component: () => import("@/views/user/PersonalInformation.vue"),
        beforeEnter: (to, from, next) => {
          if (localStorage.token === undefined) {
            showConfirmDialog({
              title: "请先登录",
              message: "你还没有登录,需要跳转到登录页吗?(*^▽^*)",
            })
              .then(() => {
                next("/login");
              })
              .catch(() => {
                next(from.path);
              });
          } else {
            next();
          }
        },
      },
    ],
  },
  //首页搜索路由配置
  {
    path: "/search",
    name: "search",
    component: () => import("@/views/tabbar/homeSon/Search.vue"),
  },
  {
    path: "/searchSon",
    name: "searchSon",
    component: () => import("@/views/tabbar/homeSon/SearchSon.vue"),
  },
  //商品详情页
  {
    path: "/detailPage",
    name: "detailPage",
    component: () => import("@/views/tabbar/homeSon/DetailPage.vue"),
  },
  // 我的订单里的商品列表 详情页
  {
    path: "/users/order/details",
    name: "details",
    component: () => import("@/views/user/details/Detail.vue"),
  },
  // 编辑地址
  {
    path: "/users/location/changeaddr",
    name: "changeaddr",
    component: () => import("@/views/user/addr/ChangeAddr.vue"),
  },
  // 新增地址
  {
    path: "/users/location/newaddr",
    name: "newaddr",
    component: () => import("@/views/user/addr/NewAddr.vue"),
  },
  // 查看更多详情
  {
    path: "/detailPageSon",
    name: "detailPageSon",
    component: () => import("@/views/tabbar/homeSon/DetailPageSon.vue"),
  },
  // 新品top.10的页面
  {
    path: "/choiceness",
    name: "choiceness",
    component: () => import("@/views/tabbar/homeSon/Choiceness.vue"),
  },
  // 立即购买跳转页面
  {
    path: "/buyDetail",
    name: "buyDetail",
    component: () => import("@/views/tabbar/homeSon/BuyDetail.vue"),
  },
  // 立即支付跳转的页面
  {
    path: "/nowPay",
    name: "nowPay",
    component: () => import("@/views/tabbar/homeSon/NowPay.vue"),
  },
  //忘记密码跳转的页面
  {
    path: "/forgetPWD",
    name: "forgetPWD",
    component: () => import("@/views/ForgetPWD.vue"),
  },
];
export default routes;
